
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DimDivision]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 drop table [dbo].[DimDivision]

GO

CREATE TABLE [dbo].[DimDivision] (
	[DivisionKey] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL,
	[DivisionIdentifier] [varchar] (20) NOT NULL,
	[DivisionName] [nvarchar] (50) NOT NULL,
	[ParentDivisionKey] [int] NOT NULL,

	CONSTRAINT [PK_Division] PRIMARY KEY CLUSTERED (
		   [DivisionKey]),

	CONSTRAINT [FK_Division_ParentDivisionKey] FOREIGN KEY ([ParentDivisionKey]) REFERENCES [dbo].[DimDivision] ([DivisionKey]) NOT FOR REPLICATION

)

GO

grant references, select, insert, delete, update on [dbo].[DimDivision] to [db_datawriter]

GO

grant select on [dbo].[DimDivision] to [public]

GO

